using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CivilizationPanel : BasePanel
{
    static readonly string path = "UI/Panel/CivilizationPanel";
    SkillCivilization civilization;
    public CivilizationPanel() : base(new UIType(path)) { }
    public override void OnEnter()
    {
        civilization = GameObject.FindWithTag("Player").GetComponentInChildren<SkillCivilization>();
        civilization.skillchoosing = true;
        Time.timeScale = 0f;
        for(int i = 0; i < 4; i++)
        {
            if (civilization.technology[i] == true)
            {

                uitool.GetOrAddComponentInChildren<Button>("technology"+(i+1).ToString()).interactable = false;
            }
        }
        for (int i = 0; i <2; i++)
        {
            if (civilization.product[i] == true)
            {

                uitool.GetOrAddComponentInChildren<Button>("production" + (i+1).ToString()).interactable = false;
            }
        }
        uitool.GetOrAddComponentInChildren<Button>("unit1").onClick.AddListener(() =>
        {
            civilization.CD = 1;
            civilization.unit1(400);        
            panelmanager.Pop();
        });
        uitool.GetOrAddComponentInChildren<Button>("technology1").onClick.AddListener(() =>
        {
            civilization.CD = 1;
            civilization.technology1(400);
            panelmanager.Pop();
        });
        uitool.GetOrAddComponentInChildren<Button>("technology2").onClick.AddListener(() =>
        {
            civilization.CD = 1;
            civilization.technology2(600);
            panelmanager.Pop();
        }); 
        uitool.GetOrAddComponentInChildren<Button>("technology3").onClick.AddListener(() =>
        {
            civilization.CD = 1;
            civilization.technology3(600);
            panelmanager.Pop();
        }); 
        uitool.GetOrAddComponentInChildren<Button>("technology4").onClick.AddListener(() =>
        {
            civilization.CD = 1;
            civilization.technology4(400);
            panelmanager.Pop();
        });
        uitool.GetOrAddComponentInChildren<Button>("production1").onClick.AddListener(() =>
        {
            civilization.CD = 1;
            civilization.production1(200);
            panelmanager.Pop();
        });
        uitool.GetOrAddComponentInChildren<Button>("production2").onClick.AddListener(() =>
        {
            civilization.CD = 1;
            civilization.production2(400);
            panelmanager.Pop();
        });
        uitool.GetOrAddComponentInChildren<Button>("culture").onClick.AddListener(() =>
        {
            civilization.CD = 1;
            civilization.culture(800);
            panelmanager.Pop();
        });
    }
    public override void OnExit()
    {
        Time.timeScale = 1f;
        civilization.skillchoosing = false;
        base.OnExit();
    }
}
